package com.asohofrucol.dto.util;

import com.asohofrucol.dto.LivestockResourceRegisterDTO;
import com.asohofrucol.model.ComboValue;
import com.asohofrucol.model.LivestockResource;
import com.asohofrucol.model.Ruat;

public class LivestockResourceHelperDto {

	public static LivestockResourceRegisterDTO convertToRegisterDTO(
			LivestockResource lr) {

		LivestockResourceRegisterDTO lrDTO = new LivestockResourceRegisterDTO();
		lrDTO.setAreaAmount(lr.getAreaAmount());
		lrDTO.setAssistanceEntity(lr.getAssistanceEntity());
		lrDTO.setAssistanceProgram(lr.getAssistanceProgram());
		lrDTO.setId(lr.getId());
		lrDTO.setModifiedDate(lr.getModifiedDate());
		lrDTO.setModifierUser(lr.getModifierUser());
		lrDTO.setNumberOfAnimals(lr.getNumberOfAnimals());
		lrDTO.setProductionAmount(lr.getProductionAmount());
		;
		lrDTO.setProductionForTheMarket(lr.getProductionForTheMarket());
		lrDTO.setProductionUnit(lr.getProductionUnit());
		lrDTO.setProductOther(lr.getProductOther());
		lrDTO.setRaceOrType(lr.getRaceOrType());
		lrDTO.setRuatId(lr.getRuat().getId());
		lrDTO.setSalesPriceAverage(lr.getSalesPriceAverage());
		lrDTO.setSaleType((lr.getComboValueSaleType() != null) ? lr
				.getComboValueSaleType().getId() : null);

		lrDTO.setSaleTypeDesc((lr.getComboValueSaleType() != null) ? lr
				.getComboValueSaleType().getDescription() : null);

		lrDTO.setSellsToNameAndSurname(lr.getSellsToNameAndSurname());
		lrDTO.setSiteForSale((lr.getComboValueSiteForSale() != null) ? lr
				.getComboValueSiteForSale().getId() : null);

		lrDTO.setSiteForSaleDesc((lr.getComboValueSiteForSale() != null) ? lr
				.getComboValueSiteForSale().getDescription() : null);

		lrDTO.setStatus(lr.getStatus());
		lrDTO.setSubProduct(lr.getSubProduct());
		lrDTO.setSubProductUse(lr.getSubProductUse());
		lrDTO.setTotalCost(lr.getTotalCost());
		lrDTO.setProduct((lr.getComboValueProduct() != null) ? lr
				.getComboValueProduct().getId() : null);
		lrDTO.setMethodOfPyment((lr.getComboValueMethodOfPyment() != null) ? lr
				.getComboValueMethodOfPyment().getId() : null);

		lrDTO.setMethodOfPymentDesc((lr.getComboValueMethodOfPyment() != null) ? lr
				.getComboValueMethodOfPyment().getDescription() : null);

		lrDTO.setMembershipTechnicalAssistancePrograms((lr
				.getComboValueMembershipTechnicalAssistancePrograms() != null) ? lr
				.getComboValueMembershipTechnicalAssistancePrograms().getId()
				: 2L);

		lrDTO.setMembershipTechnicalAssistanceProgramsDesc(lr
				.getComboValueMembershipTechnicalAssistancePrograms()
				.getDescription());

		lrDTO.setFertilizationMethod((lr.getComboValueFertilizationMethod() != null) ? lr
				.getComboValueFertilizationMethod().getId() : null);
		lrDTO.setFertilizationMethodDesc((lr.getComboValueFertilizationMethod() != null) ? lr
				.getComboValueFertilizationMethod().getDescription() : null);
		lrDTO.setAreaUnit((lr.getComboValueAreaUnit() != null) ? lr
				.getComboValueAreaUnit().getId() : null);

		lrDTO.setAreaUnitDesc((lr.getComboValueAreaUnit() != null) ? lr
				.getComboValueAreaUnit().getDescription() : null);

		lrDTO.setProductDesc(lr.getComboValueProduct().getDescription());

		return lrDTO;

	}

	public static LivestockResource converRegisterToEntity(
			LivestockResourceRegisterDTO lrDTO) {
		LivestockResource lr = new LivestockResource();

		lr.setId(lrDTO.getId());

		lr.setAreaAmount(lrDTO.getAreaAmount());

		lr.setAssistanceEntity(lrDTO.getAssistanceEntity());

		lr.setAssistanceProgram(lrDTO.getAssistanceProgram());

		lr.setModifiedDate(lrDTO.getModifiedDate());

		lr.setModifierUser(lrDTO.getModifierUser());

		lr.setNumberOfAnimals(lrDTO.getNumberOfAnimals());

		lr.setProductOther(lrDTO.getProductOther());

		lr.setProductionAmount(lrDTO.getProductionAmount());

		lr.setProductionForTheMarket(lrDTO.getProductionForTheMarket());

		lr.setProductionUnit(lrDTO.getProductionUnit());

		lr.setRaceOrType(lrDTO.getRaceOrType());

		lr.setSalesPriceAverage(lrDTO.getSalesPriceAverage());

		lr.setSellsToNameAndSurname(lrDTO.getSellsToNameAndSurname());

		lr.setStatus(lrDTO.getStatus());

		lr.setSubProduct(lrDTO.getSubProduct());

		lr.setSubProductUse(lrDTO.getSubProductUse());

		lr.setTotalCost(lrDTO.getTotalCost());

		lr.setRuat(new Ruat(lrDTO.getRuatId()));

		lr.setComboValueProduct(new ComboValue(lrDTO.getProduct()));

		lr.setComboValueFertilizationMethod(new ComboValue(lrDTO
				.getFertilizationMethod()));

		lr.setComboValueAreaUnit(new ComboValue(lrDTO.getAreaUnit()));

		lr.setComboValueSiteForSale(new ComboValue(lrDTO.getSiteForSale()));

		lr.setComboValueSaleType(new ComboValue(lrDTO.getSaleType()));

		lr.setComboValueMethodOfPyment(new ComboValue(lrDTO.getMethodOfPyment()));

		lr.setComboValueMembershipTechnicalAssistancePrograms(new ComboValue(
				lrDTO.getMembershipTechnicalAssistancePrograms()));

		return lr;

	}

}
